//
//  MBProgressHUD+HYL.m
//  MBProgressHUD-HYL
//
//  Created by acorn-net01 on 2017/5/17.
//  Copyright © 2017年 HYL. All rights reserved.
//

#import "MBProgressHUD+HYL.h"

@implementation MBProgressHUD (HYL)


+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view{

    if (view == nil) {
        view = [[UIApplication sharedApplication].windows lastObject];
    }
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    hud.labelText  = text ;
    
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    // 1秒之后再消失
    [hud hide:YES afterDelay:1];
    
}



+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view afterDelayTime:(NSInteger)delay{
    
    if (view == nil) {
        view = [[UIApplication sharedApplication].windows lastObject];
    }
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    hud.labelText  = text ;
    
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    //  随机几秒之后再消失
    [hud hide:YES afterDelay:delay];
    
}


# pragma mark -成功
+ (void)showSuccess:(NSString *)success toView:(UIView *)view;
{
    [self show:success icon:@"success" view:view];
}

+ (void)showSuccess:(NSString *)success toView:(UIView *)view afterDelay:(NSInteger)delay
{
    [self show:success icon:@"success" view:view afterDelayTime:delay];
}


# pragma mark -错误
+ (void)showError:(NSString *)error toView:(UIView *)view;
{
    [self show:error icon:@"error" view:view];
}


+ (void)showError:(NSString *)error toView:(UIView *)view afterDelay:(NSInteger)delay
{
    [self show:error icon:@"error" view:view afterDelayTime:delay];
}


+ (void)showCustom:(NSString *)text view:(UIView *)view {

    if (view == nil) {
        view = [[UIApplication sharedApplication].windows lastObject];
    }
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.dimBackground = NO ; //现实是否遮罩
    
    // 设置图片
    hud.labelText=text;
    UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"loading.png"]];
    CABasicAnimation *animation= [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animation.toValue = [NSNumber numberWithFloat:M_PI*2];
    animation.duration = 1.0;
    animation.repeatCount = 100;
    [img.layer addAnimation:animation forKey:nil];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    hud.customView = img;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
}


#pragma mark 显示一些信息
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.labelText = message;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
    hud.dimBackground = YES;
    return hud;
}

+ (void)showSuccess:(NSString *)success
{
    [self showSuccess:success toView:nil];
}

+ (void)showError:(NSString *)error
{
    [self showError:error toView:nil];
}

+ (MBProgressHUD *)showMessage:(NSString *)message
{
    return [self showMessage:message toView:nil];
}

+ (void)hideHUDForView:(UIView *)view
{
    [self hideHUDForView:view animated:YES];
}

+ (void)hideHUD
{
    [self hideHUDForView:nil];
}


+(void)showCustomAnimation:(NSString *)msg withImgArry:(NSArray *)imgArry inview:(UIView *)view{
    
    UIImageView *showImageView = [[UIImageView alloc] init];
    showImageView.animationImages = imgArry;
    [showImageView setAnimationRepeatCount:0];
    [showImageView setAnimationDuration:(imgArry.count + 1) * 0.075];
    [showImageView startAnimating];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    // 设置图片
    hud.labelText = msg;
       hud.mode = MBProgressHUDModeCustomView;
    hud.customView = showImageView;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
}

@end

